package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

public interface OrdersMapper {

    /**
     * 插入订单数据
     * @param orders
     */
    void save(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 获取orderid的mapper层方法，写在OrderMapper.java文件下
     * @param orderNumber
     * @return
     */
    @Select("select * from orders where number=#{orderNumber}")
    Long getOrderId (String orderNumber);

    /**
     * 根据订单状态查询历史订单
     * @param ordersPageQueryDTO
     * @return
     */
    List<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据id查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders selectById(Long id);

    /**
     * 根据状态统计订单数量
     * @param status
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    /**
     * 查询超时订单
     * @param pendingPayment
     * @param time
     * @return
     */
    @Select("select * from orders where status = #{pendingPayment} and order_time = #{time}")
    List<Orders> queryTimeoutOrder(Integer pendingPayment, LocalDateTime time);

    /**
     * 营业额统计
     * @param beginDate
     * @param endDate
     * @param status
     * @return
     */
    BigDecimal selectTurnover(LocalDateTime beginDate,LocalDateTime endDate,Integer status);

    /**
     * 订单数统计
     * @param beginTime
     * @param endTime
     * @param status
     * @return
     */
    Integer selectCount(LocalDateTime beginTime, LocalDateTime endTime,Integer status);

    /**
     * 商品销量
     * @param beginTime
     * @param endTime
     * @param status
     * @return
     */
    List<GoodsSalesDTO> queryTop10(LocalDateTime beginTime, LocalDateTime  endTime, Integer status);
}
